public class HelloWorld{

    public static void main(String[] args) {
        Node nodeA = new Node("a");
        Node nodeB = new Node("b");
        Node nodeC = new Node("c");
        Node nodeD = new Node("d");

        Node nodeA1 = new Node("a");
        Node nodeB1 = new Node("b");
        Node nodeC1 = new Node("c");
        Node nodeD1 = new Node("d");

        Node node = nodeA;
        node.next = nodeB;
        nodeB.next = nodeC;
        nodeC.next = nodeD;
        nodeD.next = nodeD1;
        nodeD1.next = nodeC1;
        nodeC1.next = nodeB1;
        nodeB1.next = nodeA1;
        nodeA1.next = null;


        boolean palindromeString = isPalindromeString(node);

        System.out.println(palindromeString);
    }

    public static boolean isPalindromeString(Node head) {
        if (head == null || head.next == null) {
            return true;
        }

        Node prev = null;
        Node slow = head;
        Node fast = head;

        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            Node next = slow.next;
//            反序
            slow.next = prev;
            prev = slow;
            slow = next;
        }

        if (fast != null) {
            slow = slow.next;
        }

        while (slow != null) {
            if (!slow.data.equals(prev.data)) {
                return false;
            }
            slow = slow.next;
            prev = prev.next;
        }

        return true;
    }


    static class Node {
        String data;
        Node next;
        
        public Node(String data) {
            this.data = data;
        }
    }
}